package com.mark.springboot.controller;

import com.mark.springboot.common.Result;
import com.mark.springboot.entity.Category;
import com.mark.springboot.service.CategoryService;
import org.apache.ibatis.io.ResolverUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: MARK
 * @Date: 2019/8/20 18:55
 * @Version: 1.0.0
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/category", produces = {"application/json;charset=UTF-8"})
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping
    public Result getAll(){
        List<Category> categories = categoryService.selectAll();
        Result result = new Result();
        result.setData(categories);
        return result;
    }

    @PostMapping
    public Result add(@RequestBody Category category){
        categoryService.add(category);
        return Result.ok("添加成功");
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable Integer id){
        categoryService.del(id);
        return Result.ok("删除成功");
    }

    @PutMapping
    public Result update(@RequestBody Category category){
        categoryService.update(category);
        return Result.ok("修改成功");
    }
}
